package com.yidu.service.impl;

import com.yidu.entity.SCommodity;
import com.yidu.dao.SCommodityDao;
import com.yidu.service.SCommodityService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * (SCommodity)表服务实现类
 *
 * @author wanghong
 * @since 2021-07-29 16:30:27
 */
@Service("sCommodityService")
public class SCommodityServiceImpl implements SCommodityService {
    @Autowired
    private SCommodityDao sCommodityDao;

    /**
     * 通过ID查询单条数据
     *
     * @param coid 主键
     * @return 实例对象
     */
    @Override
    public SCommodity queryById(Integer coid) {
        return this.sCommodityDao.queryById(coid);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<SCommodity> queryAllByLimit(int offset, int limit) {
        return this.sCommodityDao.queryAllByLimit(offset, limit);
    }

    /**
     * 分页查询
     * @param sCommodity
     * @return
     */
    @Override
    public List<SCommodity> findAll(SCommodity sCommodity) {
        return this.sCommodityDao.findAll(sCommodity);
    }

    @Override
    public Integer findCount(SCommodity sCommodity) {
        return this.sCommodityDao.findCount(sCommodity);
    }

    /**
     * 新增数据
     *
     * @param sCommodity 实例对象
     * @return 实例对象
     */
    @Override
    public SCommodity insert(SCommodity sCommodity) {
        this.sCommodityDao.insert(sCommodity);
        return sCommodity;
    }

    /**
     * 修改数据
     *
     * @param sCommodity 实例对象
     * @return 实例对象
     */
    @Override
    public SCommodity update(SCommodity sCommodity) {
        this.sCommodityDao.update(sCommodity);
        return this.queryById(sCommodity.getCoid());
    }

    /**
     * 通过主键删除数据
     *
     * @param coid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer coid) {
        return this.sCommodityDao.deleteById(coid) > 0;
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @Override
    public boolean deleteBatch(String[] ids) {
        return this.sCommodityDao.deleteBatch(ids)>0;
    }
}
